/*
 * @Author: new-wang
 * @Date: 2025-08-29 16:32:39
 * @LastEditors: new-wang
 * @LastEditTime: 2025-09-02 09:59:40
 * @FilePath: \nest-demo\src\module\system\user\entities\user_login_log.entity.ts
 * @Description: 用户登录记录表实体
 */
import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm'

@Index('idx_login_time', ['loginTime'], {})
@Index('idx_user_uuid', ['userUuid'], {})
@Entity('user_login_log', { schema: 'nest-demo' })
export class UserLoginLogEntity {
  @PrimaryGeneratedColumn({ type: 'bigint', name: 'id' })
  id: string

  @Column('char', { name: 'user_uuid', comment: '对应用户uuid', length: 36 })
  userUuid: string

  @Column('int', {
    name: 'system_id',
    comment: '所属系统ID',
    unsigned: true,
    nullable: true,
  })
  systemId: number

  @Column('datetime', {
    name: 'login_time',
    nullable: true,
    comment: '登录时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  loginTime: Date | null

  @Column('varchar', { name: 'login_ip', comment: '登录ip', length: 45 })
  loginIp: string

  @Column('text', { name: 'user_agent', nullable: true, comment: '代理' })
  userAgent: string | null

  @Column('tinyint', {
    name: 'login_result',
    nullable: true,
    comment:
      '1:成功, 0:失败\r\n2025-8-29 10:38:18\r\n暂时不用此字段，只记录登录成功的',
  })
  loginResult: number | null

  @Column('varchar', {
    name: 'failure_reason',
    nullable: true,
    comment: '故障原因',
    length: 255,
  })
  failureReason: string | null
}
